import { defineStore } from "pinia";
import { getPickerListAPI } from "@/api/modules/city/cityPicker/api";

export const usePickerStore = defineStore({
  id: "geeker-picker",
  state: () => ({
    // 当前页面的 router name，用来做按钮权限筛选
    tag: {
      new: 0,
      examine: 0,
      passed: 0,
      notPassed: 0,
      cancel: 0
    }
  }),
  actions: {
    // Get AuthButtonList
    async setTagsViewNew() {
      const { total } = await getPickerListAPI({
        fullName: "",
        auditStatus: "0",
        phonenumber: "",
        province: JSON.parse(localStorage.getItem("userInfo") as string).province,
        city: JSON.parse(localStorage.getItem("userInfo") as string).city,
        pageNum: 1,
        pageSize: 10
      });
      if (total) {
        this.tag.new = Number(total);
      }
    },
    async setTagsViewExamine() {
      const { total } = await getPickerListAPI({
        fullName: "",
        phonenumber: "",
        auditStatus: "1",
        province: JSON.parse(localStorage.getItem("userInfo") as string).province,
        city: JSON.parse(localStorage.getItem("userInfo") as string).city,
        pageNum: 1,
        pageSize: 10
      });
      if (total) {
        this.tag.examine = Number(total);
      }
    },
    async setTagsViewPassed() {
      const { total } = await getPickerListAPI({
        fullName: "",
        phonenumber: "",
        auditStatus: "2",
        province: JSON.parse(localStorage.getItem("userInfo") as string).province,
        city: JSON.parse(localStorage.getItem("userInfo") as string).city,
        pageNum: 1,
        pageSize: 10
      });
      if (total) {
        this.tag.passed = Number(total);
      }
    },
    async setTagsViewNotPassed() {
      const { total } = await getPickerListAPI({
        fullName: "",
        phonenumber: "",
        auditStatus: "3",
        province: JSON.parse(localStorage.getItem("userInfo") as string).province,
        city: JSON.parse(localStorage.getItem("userInfo") as string).city,
        pageNum: 1,
        pageSize: 10
      });
      if (total) {
        this.tag.notPassed = Number(total);
      }
    },
    async setTagsViewCancel() {
      const { total } = await getPickerListAPI({
        fullName: "",
        phonenumber: "",
        auditStatus: "4",
        province: JSON.parse(localStorage.getItem("userInfo") as string).province,
        city: JSON.parse(localStorage.getItem("userInfo") as string).city,
        pageNum: 1,
        pageSize: 10
      });
      if (total) {
        this.tag.cancel = Number(total);
      }
    }
  }
});
